import * as api from "&/api";
export default {
  namespaced: true,
  state: {
    products: {},
  },
  mutations: {
    SET_PRODUCT(state, paylode) {
      let target = state.products.find((j) => j.id === paylode.id);
      if (target) {
        target.inventory--;
      }
    },
    SET_PRODUCT_DATA(state, paylode) {
      state.products = paylode;
    },
    RECOVER(state, paylode) {
      console.log(paylode);
      let target = state.products.find((j) => j.id === paylode);
      // let tarGet = state.pay
      console.log(target);
      if (target) {
        target.inventory++;
      }
    },
  },
  actions: {
    async FETCH_PRODUCT(context) {
      let res = await api.fetchProduct();
      console.log(res);
      context.commit("SET_PRODUCT_DATA", res.data);
    },
    COM_RECOVER(context, paylode) {
      context.commit("RECOVER", paylode.id);
    },
  },
  getters: {},
  modules: {},
};
